package com.ai.main.config;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.client.advisor.vectorstore.QuestionAnswerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.prompt.PromptTemplate;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.ai.template.st.StTemplateRenderer;
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.ai.vectorstore.SearchRequest;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 功能描述
 *
 * @author: jichao.huang
 * @date: 2025年05月27日 23:07
 */
@Configuration
public class ChatConfig {
    final ChatModel chatModel;

    public ChatConfig(ChatModel chatModel){
        this.chatModel = chatModel;
    }

    @Bean
    //public ChatClient chatClient(ChatMemory chatMemory, VectorStore vectorStore, ToolCallbackProvider toolCallbackProvider) {
    public ChatClient chatClient(ChatMemory chatMemory, VectorStore vectorStore, ToolCallbackProvider toolCallbackProvider) {

        return ChatClient.builder(chatModel)
                //.defaultSystem("假如你是特朗普，接下来的对话必须以特朗普的语气进行")
                //.defaultAdvisors(MessageChatMemoryAdvisor.builder(chatMemory).build(), new QuestionAnswerAdvisor(vectorStore), new SimpleLoggerAdvisor())
                .defaultAdvisors(
                        //MessageChatMemoryAdvisor.builder(chatMemory).build(),
                        //QuestionAnswerAdvisor.builder(vectorStore)
                                //.searchRequest(SearchRequest.builder()
                                        //.filterExpression("type = 'spring'")
                                        //.build()
                                //).build(),
                        new SimpleLoggerAdvisor())
                //.defaultTools(toolCallbackProvider)
                .build();
    }

    /**
    @Bean
    public ChatMemory  chatMemory() {
        return new InMemoryChatMemory();
    }
     **/

    @Bean
    public ChatClient openAiChatClient(OpenAiChatModel chatModel) {
        return ChatClient.create(chatModel);
    }


    /**
    @Bean
    public ChatClient anthropicChatClient(AnthropicChatModel chatModel) {
        return ChatClient.create(chatModel);
    }
    **/
}
